Well, this is getting tricky.

Kinja'd!!! "Wheelerguy" (wheelerguy)
08/29/2018 at 08:00 • Filed to: computerlopnik, Java

Kinja'd!!!0 Kinja'd!!! 12
Kinja'd!!!

I can see what I am doing wrong, but what exactly am I supposed to do? Surely I have to put up a newScanner line on for each module .


DISCUSSION (12)


Kinja'd!!! pip bip - choose Corrour > Wheelerguy
08/29/2018 at 08:03

Kinja'd!!!0

good question for Nibby, as i’m clueless.


Kinja'd!!! Nibby > Wheelerguy
08/29/2018 at 08:11

Kinja'd!!!3

you’re missing the install(Windows95) function


Kinja'd!!! Wheelerguy > Nibby
08/29/2018 at 08:14

Kinja'd!!!0

I’m doing this on 3.1, mate.


Kinja'd!!! CalzoneGolem > Wheelerguy
08/29/2018 at 08:16

Kinja'd!!!0

Java is a scourge on mankind


Kinja'd!!! pip bip - choose Corrour > CalzoneGolem
08/29/2018 at 08:22

Kinja'd!!!0

how come?


Kinja'd!!! CalzoneGolem > pip bip - choose Corrour
08/29/2018 at 08:24

Kinja'd!!!1

Because I don’t understand it. I learned dozens of languages in college but Java just doesn’t take for me . Javascript I can fake my way through but plain Java is the worst.


Kinja'd!!! Echo51 > Wheelerguy
08/29/2018 at 08:26

Kinja'd!!!1

There’s... quite a bit going on here. Start from the top and work your way down. First is double-defined variable, so i guess you can remove int so you set the variable to the value instead of redefining it. Next up is wrong type, so fix that by having it return correctly, or change the comparison to be “ correct”. the others seem to be string as int issues, a quick google should help you on those.


Kinja'd!!! BlurpleToyotaDishwasher > Wheelerguy
08/29/2018 at 08:27

Kinja'd!!!1

the left hand side of line 14 is declaring a variable that already exist.
Also it looks like you’re mixing up service and modOne when you’re calling nextInt which is why you’re getting the derefenced errors and the compar i s o n error.

(Also wasn’t Scanne r deprecate d y e a r s a g o ? )


Kinja'd!!! Wheelerguy > BlurpleToyotaDishwasher
08/29/2018 at 08:39

Kinja'd!!!0

(Also wasn’t Scanner deprecated years ago?)

No idea. The Java in school 1.8.0_77 , though Scanner still works on my Win10 1.8.0_172.

So I just have to have a different declaration on L14 and switch service and modOne?


Kinja'd!!! BlurpleToyotaDishwasher > Wheelerguy
08/29/2018 at 09:44

Kinja'd!!!2

It’s still in there, but I’m pretty sure it’s been best practice not to use it for the last few years (it’s been a while since I did stuff in Java so I can’t remember what the replacement was). I’d imagine it’s fine for the intro class though.

When you’re declaring on ln 14 , there’s already a declaration further up (in the first 9 lines that are cut off the screenshot) with the name modOne. Remove the type from the left hand side so it’s an assignment not a declaration, or check if you meant to call this something else (your naming is really not clear to read).

Then in line 16 & 39, you’re trying to compare the scanner itself instead of the integer values you’ve got from it to 1 and 2

Then the errors where you’re trying to call modOne.nextInt() etc. are because it’s an int, so doesn’t have a nextInt method - int is a primitive type which should be the giveaway there - that needs to be service.nextInt()

I have a feeling that you do that, and you’ll get a null pointer exception on modTwo because I can’t see it being assigned anywhere. What is that supposed to be?

Also, sort your indentation, variable naming and declaration out. It’s making it hard to read:
Camel case
clear names (full words, avoid cryptic names like modOne and names that suggest something isn’t what it is, like calling your Scanner service)
Declare one thing per line, and declare where you’ve got something to assign, don’t do it in a clump at the top and leave it null.
Also avoid magic numbers like the 1 and 2 in the ifs - declare them private s t a t i c final at the top of the c l a s s , o r f i n a l a t t h e t o p o f t h e method with a clear name.


Kinja'd!!! Wheelerguy > BlurpleToyotaDishwasher
08/29/2018 at 10:21

Kinja'd!!!0

So I was able to remove the ln14 error and if/else Scanner type bits , plus the dereference is gone, leaving me with this:

Kinja'd!!!


Kinja'd!!! Wheelerguy > BlurpleToyotaDishwasher
08/29/2018 at 10:53

Kinja'd!!!0

Wait no I got it! I got it to run smoothly. Just.

Kinja'd!!!

Only one error and it’s the Employee Name entry being right next to Total Hours. Seems easy to debug but ugh.